package FactoryMethod;

public class AbstractFactoryTest {
    public static void main(String[] args) {
        try{
            Product a;
            AbstractFactory af;
            af = (AbstractFactory) ReadXML1.getObject();
            a = af.newProduct();
            a.show();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
//抽象产品：提供产品接口
interface Product{
    public void show();
}
//具体产品1、2，实现抽象产品中的抽象方法
class ConcreateProduct1 implements Product{
    @Override
    public void show() {
        System.out.println("具体产品1的显示");
    }
}
class ConcreateProduct2 implements Product{
    @Override
    public void show() {
        System.out.println("具体产品2的显示");
    }
}
//抽象工厂
interface AbstractFactory{
    public Product newProduct();
}
//具体工厂1、2，实现生成方法
class ConcreateFactory1 implements AbstractFactory{
    @Override
    public Product newProduct() {
        System.out.println("具体工厂1生成->具体产品1");
        return new ConcreateProduct1();
    }
}
class ConcreateFactory2 implements AbstractFactory{
    @Override
    public Product newProduct() {
        System.out.println("具体工厂2生成->具体产品2");
        return new ConcreateProduct2();
    }
}
